package com.bdqn.service;

import com.bdqn.dao.SysUserMapper;
import com.bdqn.pojo.SysUser;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * SysUserService服务层实现类
 *
 */
@Scope("prototype") // 每次请求都创建一个新的实例
@Service
//@Service("sysUserService") // 注册为一个Service层的Bean
public class SysUserServiceImpl implements SysUserService {

    //@Autowired // @Resource // 使用注解的方式将DAO层的Bean注入
    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public List<SysUser> getList(SysUser sysUser) {
        try {
            return sysUserMapper.selectSysUserList(sysUser);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 保存用户
     *
     * @param sysUser
     * @return
     */
    // @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public boolean add(SysUser sysUser) {
        sysUserMapper.add(sysUser);
        sysUserMapper.add(sysUser);
        return true;
    }

    @Override
    public int delete(Integer id) {
        try {
            return sysUserMapper.delete(id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public boolean update(SysUser sysUser) {
        sysUserMapper.update(sysUser);
        return true;
    }

    @Override
    public SysUser login(String account, String password) {
        return sysUserMapper.queryByAccountAndPwd(account, password);
    }
}